package com.ruoyi.behavior.mapper;

import com.ruoyi.behavior.domain.Replies;
import com.ruoyi.behavior.domain.VerReviewImage;
import com.ruoyi.behavior.domain.dto.*;
import com.ruoyi.behavior.domain.dto.filter.FilterDto;
import com.ruoyi.behavior.domain.dto.filter.SkuFilterDto;
import com.ruoyi.behavior.domain.dto.filter.SupFilterDto;
import com.ruoyi.behavior.domain.vo.AmountOfRateVo;
import com.ruoyi.behavior.domain.vo.RepliesVo;
import com.ruoyi.behavior.domain.vo.ReviewVo;
import com.ruoyi.behavior.domain.vo.VerReviewVo;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 用户行为Mapper接口
 *
 * @author ruoyi
 * @date 2025-09-10
 */
@Mapper
public interface VerReviewMapper {

    /**
     * 根据categoryId获取评论
     *
     * @param categoryId
     * @return
     */
    List<CategoryReviewDto> getReviewByCategoryId(Long categoryId);

    List<CategoryReviewDto> pageList(CategoryReviewDto categoryReviewDto);

    List<SkuReviewDto> getSkuInfo(Long skuId);

    @Select("select max(id) from ver_review")
    Long getMaxId();

    int add(VerReviewVo verReviewVo);

    /**
     * 插入评论图片
     *
     * @param verReviewImage
     * @return
     */
    int addReviewImage(VerReviewImage verReviewImage);

    /**
     * 获取ver_review_image表的最大ID
     *
     * @return
     */
    @Select("select max(id) from ver_review_image")
    Long getMaxImageId();

    /**
     * 根据sku_id获取统计信息与评论列表
     *
     * @param skuId
     * @return
     */
    List<SkuReviewListDto> getSkuReviewList(Long skuId, SkuFilterDto filter);

    /**
     * 根据sku_id获取评论图片URLs
     *
     * @param skuId
     * @return
     */
    @MapKey("id")
    List<Map<String, Object>> getUrls(Long skuId);

    /**
     * 根据review_id获取评论图片URLs
     *
     * @param reviewId
     * @return
     */
    @MapKey("id")
    List<Map<String, Object>> getUrlsByReviewId(Long reviewId);

    /**
     * 根据sku_id获取评分统计
     *
     * @param skuId
     * @return
     */
    List<AmountOfRateVo> getRateStatistics(Long skuId);

    List<SpuReviewDto> getSpuReviewList(Long spuId, SupFilterDto filter);

    List<RepliesVo> getReplies(Long reviewId);

    List<UserReviewDto> getOrderItemAndReview(Long userId, FilterDto filter);

    List<ReviewVo> getReviewList(Long userId);

    int edit(VerReviewVo verReviewVo);

    Integer deleteReviewImage(Long id);

    @Select("select user_id from ver_review where id=#{reviewId}")
    Long getReplyToUserId(Long reviewId);

    @Select("select max(id) from ver_replies")
    Long getMaxReplyId();

    int reply(Replies replies);
}
